<?php
/*
 * @Descripttion: 
 * @version: 1.0
 * @Author: Sam
 * @Date: 2022-01-17 19:26:43
 * @LastEditors: Sam
 * @LastEditTime: 2022-11-21 14:20:50
 */

namespace app\api\controller;
use think\facade\Db;
use app\admin\model\{User as UserModel};
use app\common\api\WeChat;
use think\facade\Env;
use hg\apidoc\annotation as Apidoc;
use Dompdf\Dompdf;
use app\common\api\Feishu;

/**
 * @Apidoc\Title("用户管理")
 */
 
class User extends ApiBase {


       /**
     * @Apidoc\Title("获取用户token")
     * @Apidoc\Url("/api/get_token")
     * @Apidoc\Desc("需要token验证")
     * @Apidoc\Method("post")
     * @Apidoc\Param("uid", type="int",desc="用户id")
     * @Apidoc\Returned("token", type="string", desc="token")
     */
    public function get_token(){
        $uid = input('uid');
        $user = UserModel::find($uid);
        $jwt = \Jwt::getInstance();
        $jwt->setKey(Env::get('TOKEN_KEY')); //设置秘钥 每个项目务必更换
        $jwt->setIss(Env::get('TOKEN_ISS'));  //签发者  可以写项目名或者开发者姓名
        $jwt->setIat(time()); //签发时间
        $jwt->setExp(time() + 60*60*24 * 7); //过期时间
        $jwt->setClaim(['user_token'=>md5($user['openid'])]); //储存数据
        $token = $jwt->getToken();
        json_response(200,'success',$token);
    }

           /**
     * @Apidoc\Title("获取用户详情")
     * @Apidoc\Url("/api/user_detail")
     * @Apidoc\Desc("需要token验证")
     * @Apidoc\Method("get")
     * @Apidoc\Returned("id", type="int", desc="用户id")
     * @Apidoc\Returned("nickname", type="string", desc="用户昵称")
     * @Apidoc\Returned("avatar", type="string", desc="用户头像")
     * @Apidoc\Returned("mobile", type="string", desc="用户手机号")
     */
    public function user_detail(){
        $uid = $this->get_user_id();
        $user_info = UserModel::where('id',$uid)->with(['auth'])->field('id,nickname,avatar,mobile,auth_status')->find();
        json_response(200,'success',$user_info);
    }








    public function upload_img(){
        $file_servrt = new \app\admin\controller\Upload();
        $file_servrt->upload_file();
    }
}